#include "M3GMath.hpp"
#include <iostream>
using namespace std;
using namespace m3g;


unsigned int m3g::adler32 (const unsigned char* data, int len)
{
    unsigned int a = 1, b = 0;
    while (len > 0) {
        int tlen = len > 5550 ? 5550 : len;
        len -= tlen;
        do {
            a += *data++;
            b += a;
        } while (--tlen);
        a %= 65521;
        b %= 65521;
    }
    return (b << 16) | a;


}


